package com.lei.yohuo001java.fragmentyouhuo;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.google.android.material.tabs.TabLayout;
import com.lei.mvp_retrofitlibrary.mvp.view.BaseFragment;
import com.lei.yohuo001java.R;
import com.lei.yohuo001java.adapter.MyAdapterViewPage;
import com.lei.yohuo001java.one_fragment.AFragment;
import com.lei.yohuo001java.one_fragment.BFragment;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.RefreshState;
import com.scwang.smartrefresh.layout.listener.OnMultiPurposeListener;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class OneFragment extends BaseFragment {
    private SmartRefreshLayout smart;
    private TabLayout slidingTabLayout;
    private ViewPager actVp;
    private LinearLayout actMainSearchLayout;
    private MyAdapterViewPage viewPageAdapter;
    private List<Fragment> list = new ArrayList<>();
    private List<String> titles = new ArrayList<>();
    private AFragment aFragment;
    private BFragment bFragment;


    @Override
    public int bindlayout() {
        return R.layout.fragment_one;
    }

    @Override
    public void initView() {
        smart = (SmartRefreshLayout) findViewById(R.id.smart);
        slidingTabLayout = (TabLayout) findViewById(R.id.sliding_tab_layout);
        actVp = (ViewPager) findViewById(R.id.act_vp);
        actMainSearchLayout = (LinearLayout) findViewById(R.id.act_main_search_layout);
        aFragment = new AFragment();
        bFragment = new BFragment();
    }

    @Override
    public void initData() {
        smart.setOnMultiPurposeListener(new OnMultiPurposeListener() {
            @Override
            public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
                actMainSearchLayout.setAlpha(1-percent);
            }

            @Override
            public void onHeaderReleased(RefreshHeader header, int headerHeight, int maxDragHeight) {

            }

            @Override
            public void onHeaderStartAnimator(RefreshHeader header, int headerHeight, int maxDragHeight) {

            }

            @Override
            public void onHeaderFinish(RefreshHeader header, boolean success) {

            }

            @Override
            public void onFooterMoving(RefreshFooter footer, boolean isDragging, float percent, int offset, int footerHeight, int maxDragHeight) {

            }

            @Override
            public void onFooterReleased(RefreshFooter footer, int footerHeight, int maxDragHeight) {

            }

            @Override
            public void onFooterStartAnimator(RefreshFooter footer, int footerHeight, int maxDragHeight) {

            }

            @Override
            public void onFooterFinish(RefreshFooter footer, boolean success) {

            }

            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                refreshLayout.finishLoadMore(1000);
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                refreshLayout.finishRefresh(1000);
            }

            @Override
            public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {

            }
        });
        list.add(aFragment);
        list.add(bFragment);
        titles.add("有货");
        titles.add("秒杀");
        viewPageAdapter = new MyAdapterViewPage(getActivity().getSupportFragmentManager(),list,titles);
        actVp.setAdapter(viewPageAdapter);
        slidingTabLayout.setupWithViewPager(actVp);
    }

    @Override
    public void showToast(String msg) {

    }
}
